import time

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By

name= input("请输入你要搜索的内容：")
driver = webdriver.Chrome(service=Service('D:\\myproject\\feng-huang\\1.自动化\\1.selenium\\chromedriver.exe'))
driver.maximize_window()
for i in range(1, 52):
    driver.get(f'https://s.51sole.com/Search.aspx?q=%e5%86%9c%e4%b8%9a&page={i}')
    # # 输入搜索内容
    # driver.find_element(By.XPATH, '/html/body/div[4]/div/div[2]/div[2]/input[1]').send_keys(name)
    # driver.find_element(By.XPATH, '/html/body/div[4]/div/div[2]/div[2]/input[2]').click()
    count = 0
    for j in range(1, 25):
        count += 1
        conpanys = driver.find_element(By.XPATH, f'//*[@id="main"]/div[1]/div[{j}]/div/div/div/div[1]/p[1]/a')
        conpany = conpanys.text
        conpany_url = conpanys.get_attribute('href')
        print(count,conpany,conpany_url)
        driver.execute_script("window.scrollBy(0,10000)")
        driver.find_element(By.LINK_TEXT,'下一页')
        time.sleep(2)






time.sleep(20)